/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LoginForm.java
 *
 * Created on Nov 8, 2012, 11:55:06 PM
 */
package Form;

// import Boundary.User;
import Boundary.TU;
import Control.SiswaControl;
import Table.SiswaTabelModel;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Fave
 */
public class SiswaLihatPresensi extends javax.swing.JFrame {

    /** Creates new form LoginForm */
    public SiswaLihatPresensi() {
        initComponents();
        setTitle("Sistem Presensi Akademik SMS Gateway");
//        GregorianCalendar g = new GregorianCalendar();
//        String str = Carinama.getText();

        try {
            List <TU> siswa = (List<TU>) SiswaControl.getKoneksi().getAllpresensi();
            SiswaTabelModel model = new SiswaTabelModel(siswa);
            TableCariSiswa.setModel(model);

        } catch (SQLException ex) {
            Logger.getLogger(SiswaLihatPresensi.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        Carinama = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        keluarbutt = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TableCariSiswa = new javax.swing.JTable();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        Carinama.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                CarinamaKeyPressed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Rockwell", 1, 14));
        jLabel1.setText("Cari Nama ");

        keluarbutt.setText("Keluar");
        keluarbutt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                keluarbuttActionPerformed(evt);
            }
        });

        TableCariSiswa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Nama", "NIS", "Kelas", "Ijin", "Sakit", "Tidak hadir"
            }
        ));
        jScrollPane1.setViewportView(TableCariSiswa);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel1)
                .addGap(28, 28, 28)
                .addComponent(Carinama, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addGap(265, 265, 265))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(42, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(keluarbutt)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 549, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(47, 47, 47))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(Carinama, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(keluarbutt)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void keluarbuttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keluarbuttActionPerformed
       LoginForm l = new LoginForm();
        dispose();
      

    }//GEN-LAST:event_keluarbuttActionPerformed

    private void CarinamaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CarinamaKeyPressed
         String cari = Carinama.getText();
         
        if (evt.getKeyCode()==10) {
      
      try {
            List <TU> siswa = (List<TU>) SiswaControl.getKoneksi().getcari(cari);
            SiswaTabelModel model = new SiswaTabelModel(siswa);
            TableCariSiswa.setModel(model);

        } catch (SQLException ex) {
            Logger.getLogger(SiswaLihatPresensi.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }//GEN-LAST:event_CarinamaKeyPressed

    public

    static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SiswaLihatPresensi().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Carinama;
    private javax.swing.JTable TableCariSiswa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton keluarbutt;
    // End of variables declaration//GEN-END:variables
}
